package org.yoki.edu.portal.core.trace.domain;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.yunzhitx.cloud.common.model.PageResult;
import com.yunzhitx.cloud.common.model.ddd.AbstractEntity;
import com.yunzhitx.cloud.common.model.ddd.InstanceFactory;
import com.yunzhitx.cloud.common.model.exception.Shift;
import lombok.Data;

import java.util.Date;

import org.yoki.edu.portal.core.exception.BasicRestStatus;
import org.yoki.edu.portal.core.trace.infra.TraceClusterRepository;
import tk.mybatis.mapper.entity.Example;

import javax.persistence.Column;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.List;

/**
 * 代码生成器自动生成
 * Date:2018-2-6 13:41:36
 *
 * @author
 */
@Data
@Table(name = "tra_trace_cluster")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class TraceCluster extends AbstractEntity<TraceClusterRepository> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 区域id
     */
    @Column(name = "fd_areaId")
    private Integer areaId;
    /**
     * 楼层
     */
    @Column(name = "fd_floorId")
    private Integer floorId;
    /**
     * 集群名称
     */
    @Column(name = "fd_name")
    private String name;
    /**
     * 别名(预留)
     */
    @Column(name = "fd_alias")
    private String alias;
    /**
     * 简介
     */
    @Column(name = "fd_introduce")
    private String introduce;
    /**
     * 详情
     */
    @Column(name = "fd_detail")
    private String detail;
    /**
     * apMac
     */
    @Column(name = "fd_apMac")
    private String apMac;
    /**
     * 地址
     */
    @Column(name = "fd_address")
    private String address;
    /**
     * 纬度
     */
    @Column(name = "fd_latitude")
    private String latitude;
    /**

     */
    @Column(name = "fd_longtitude")
    private String longtitude;
    /**
     * 是否是端点(出入口、电梯)，是：1(true)，否：0(false)
     */
    @Column(name = "fd_isEndpoint")
    private Boolean isEndpoint;
    /**
     * 备注
     */
    @Column(name = "fd_remark")
    private String remark;

    public TraceCluster() {
    }

    public TraceCluster(Integer id) {
        setId(id);
    }

    @Override
    public Serializable getKey() {
        return getId();
    }

    @Override
    public boolean existed() {
        return false;
    }

    private static TraceClusterRepository traceClusterRepository;

    public static TraceClusterRepository getTraceClusterRepository() {
        if (null == traceClusterRepository) {
            traceClusterRepository = InstanceFactory.getInstance(TraceClusterRepository.class);
        }
        return traceClusterRepository;
    }

    /* ************************************************************************************ *
       ***************************************  增  ***************************************
    * ************************************************************************************* */

    public void save() {
        /*
        if (existed()) {
            Shift.fatal(BasicRestStatus.repeatDataErrorStatus);
        }
        */
        getTraceClusterRepository().insert(this);
    }

    /* ************************************************************************************ *
       ***************************************  删  ***************************************
    * ************************************************************************************* */

    /**
     * 根据ID删除组件<br>
     * 同时删除所有的组件参数、组件内元件参数
     *
     * @param id
     */
    public static void deleteById(Integer id) {
        if (null == id) {
            Shift.fatal(BasicRestStatus.paramNullErrorStatus);
        }
        getTraceClusterRepository().deleteByPrimaryKey(id);
    }

    /* ************************************************************************************ *
       ***************************************  改  ***************************************
    * ************************************************************************************* */

    /**
     * 根据Id，更新TraceCluster
     *
     * @param
     * @return
     */
    public void update() {
        getTraceClusterRepository().updateByPrimaryKeySelective(this);
    }

    /* ************************************************************************************ *
       ***************************************  查  ***************************************
    * ************************************************************************************* */

    /**
     * 根据apMac查询TraceCluster
     *
     * @param apMac
     * @return
     */
    public static TraceCluster selectDetailByApMac(String apMac) {
        Example e = new Example(TraceCluster.class);
        e.createCriteria().andEqualTo("apMac", apMac);
        List<TraceCluster> list = getTraceClusterRepository().selectByExample(e);
        if (null != list && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    /**
     * 根据查询条件查询分页列表
     *
     * @param page
     * @return
     */

    public PageResult<TraceCluster> selectPageByQuery(PageResult page) {
    /*
        TraceClusterPageQueryDTO dto = new TraceClusterPageQueryDTO();
        // TODO 设置dto参数
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        PageInfo<TraceCluster> pageInfo = new PageInfo<>(getTraceClusterRepository().selectPageByQuery(dto));
        page.setTotal(pageInfo.getTotal());
        page.setPageData(pageInfo.getList());
        return page;
    */
        return null;
    }


}